Skip to main content

Updating a Tracker

Once a tracker is running, you'll want to feed it with new detections so it can update the tracks. Typically, you would update the tracker each time your model produces an inference (for example, each frame). Using the SDK, you call the update function and provide the tracker ID and the new detections.

from uuid import uuid4
from datetime import UTC, datetime

from chariot import tracker as tracking_service

project_id = "<The project the tracker resides in>"
model_id = "<The id of the model inferring over imagery>"
inference_id = "<The id of the inference returned by the model>"

# Update the unitless point tracker
tracking_service.update_tracker(tracking_service.NewUpdateTrackerRequest(
tracker_id=unitless_point_tracker.tracker_id,
external_input=tracking_service.ExternalTrackerInput(
project_id=project_id,
model_id=model_id,
inference_id=inference_id,
ts=datetime.now(UTC).isoformat(),
sequence_number=0,
),
points_unitless=[
tracking_service.UnitlessPoint(
id=str(uuid4()),
label="car",
score=0.95,
x=10,
y=20,
covariance=[[1.0, 0.0], [0.0, 1.0]],
),
tracking_service.UnitlessPoint(
id=str(uuid4()),
label="truck",
score=0.8,
x=105,
y=15,
covariance=[[1.0, 0.0], [0.0, 1.0]],
)
]
)
)
print(f"Updated Unitless Point Tracker with ID: {unitless_point_tracker.tracker_id}")

# Update the latitude/longitude point tracker
tracking_service.update_tracker(tracking_service.NewUpdateTrackerRequest(
tracker_id=latitude_longitude_point_tracker.tracker_id,
external_input=tracking_service.ExternalTrackerInput(
project_id=project_id,
model_id=model_id,
inference_id=inference_id,
ts=datetime.now(UTC).isoformat(),
sequence_number=0,
),
points_lat_long=[
tracking_service.LatLongPoint(
id=str(uuid4()),
label="truck",
score=0.8,
latitude=45.0,
longitude=45.0,
covariance=[[1.0, 0.0], [0.0, 1.0]],
),
tracking_service.LatLongPoint(
id=str(uuid4()),
label="van",
score=0.99,
latitude=45.1,
longitude=45.3,
covariance=[[1.0, 0.0], [0.0, 1.0]],
)
],
)
)
print(f"Updated Latitude/Longitude Point Tracker with ID: {latitude_longitude_point_tracker.tracker_id}")

# Update the utm point tracker
tracking_service.update_tracker(tracking_service.NewUpdateTrackerRequest(
tracker_id=utm_point_tracker.tracker_id,
external_input=tracking_service.ExternalTrackerInput(
project_id=project_id,
model_id=model_id,
inference_id=inference_id,
ts=datetime.now(UTC).isoformat(),
sequence_number=0,
),
points_utm=[
tracking_service.UTMPoint(
id=str(uuid4()),
label="car",
score=0.95,
northing=3349013,
easting=621844,
zone="14N",
covariance=[[1.0, 0.0], [0.0, 1.0]],
),
tracking_service.UTMPoint(
id=str(uuid4()),
label="car",
score=0.95,
northing=3349873,
easting=621813,
zone="14N",
covariance=[[1.0, 0.0], [0.0, 1.0]],
)
],
)
)
print(f"Updated UTM Point Tracker with ID: {utm_point_tracker.tracker_id}")

# Update the unitless box tracker
tracking_service.update_tracker(tracking_service.NewUpdateTrackerRequest(
tracker_id=unitless_box_tracker.tracker_id,
external_input=tracking_service.ExternalTrackerInput(
project_id=project_id,
model_id=model_id,
inference_id=inference_id,
ts=datetime.now(UTC).isoformat(),
sequence_number=0,
),
boxes_unitless=[
tracking_service.UnitlessBox(
id=str(uuid4()),
label="car",
score=0.95,
x=50.0,
y=100.0,
w=10.0,
h=20.0,
covariance=[
[1.0, 0.0, 0.0, 0.0],
[0.0, 1.0, 0.0, 0.0],
[0.0, 0.0, 1.0, 0.0],
[0.0, 0.0, 0.0, 1.0],
],
),
tracking_service.UnitlessBox(
id=str(uuid4()),
label="bus",
score=0.65,
x=100.0,
y=200.0,
w=50.0,
h=30.0,
covariance=[
[1.0, 0.0, 0.0, 0.0],
[0.0, 1.0, 0.0, 0.0],
[0.0, 0.0, 1.0, 0.0],
[0.0, 0.0, 0.0, 1.0],
],
),
],
)
)
print(f"Updated Unitless Box Tracker with ID: {unitless_box_tracker.tracker_id}")

# Update the latitude/longitude box tracker.
tracking_service.update_tracker(tracking_service.NewUpdateTrackerRequest(
tracker_id=latitude_longitude_box_tracker.tracker_id,
external_input=tracking_service.ExternalTrackerInput(
project_id=project_id,
model_id=model_id,
inference_id=inference_id,
ts=datetime.now(UTC).isoformat(),
sequence_number=0,
unitless_box_localization_metadata=tracking_service.UnitlessBoxLocalizationMetadata(
image_height=1080,
image_width=1920,
platform_pitch_angle=3.0,
platform_roll_angle=0.0,
platform_heading_angle=90.0,
sensor_horizontal_field_of_view=3.0,
sensor_vertical_field_of_view=1.7,
sensor_relative_azimuth_angle=0.0,
sensor_relative_elevation_angle=-20.0,
sensor_relative_roll_angle=0.0,
sensor_latitude=41.0957,
sensor_longitude=-104.8700,
sensor_true_altitude=3000.0,
)
),
boxes_unitless=[
tracking_service.UnitlessBox(
id=str(uuid4()),
label="car",
score=0.95,
x=50.0,
y=100.0,
w=10.0,
h=20.0,
covariance=[
[1.0, 0.0, 0.0, 0.0],
[0.0, 1.0, 0.0, 0.0],
[0.0, 0.0, 1.0, 0.0],
[0.0, 0.0, 0.0, 1.0],
],
),
tracking_service.UnitlessBox(
id=str(uuid4()),
label="bus",
score=0.65,
x=100.0,
y=200.0,
w=50.0,
h=30.0,
covariance=[
[1.0, 0.0, 0.0, 0.0],
[0.0, 1.0, 0.0, 0.0],
[0.0, 0.0, 1.0, 0.0],
[0.0, 0.0, 0.0, 1.0],
],
),
],
)
)
print(f"Updated Latitude/Longitude Box Tracker with ID: {latitude_longitude_box_tracker.tracker_id}")

In this code, we call tracking_service.update_tracker(update_payload) to send the update. This triggers the object tracking service to perform one update cycle internally as described earlier: It will match these detections to existing tracks (if any) and update/create/terminate tracks accordingly.

The update_tracker call does not return the updated tracks directly. In our example above, since this is likely the first update after creation, the tracker had no existing tracks, so it will create new tracks for each detection. If we call the update function again with new detections from the next frame, the tracker will attempt to match them.